package com.msc.mc.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class PropertiesUtil {
	public static final PropertiesUtil INSTANCE = new PropertiesUtil();

	public static PropertiesUtil getInstance() {
		return INSTANCE;
	}
	
	public static String readLocalAddress(String path,
			String propertiesName) {

		InputStream is = PropertiesUtil.class.getClassLoader()
				.getResourceAsStream(path);

		Properties p = new Properties();
		try { 
			p.load(is);
			return p.getProperty(propertiesName);

		} catch (IOException e) {
			e.printStackTrace();
		} finally {

			if (null != is) {
				try {
					is.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return null;
	}
 

	/**
	 * 1.使用getSourceAsStream读取配置文件
	 */
	public static String readPropertiesByGetSourceAsStream(String path,
			String propertiesName) {

		InputStream is = PropertiesUtil.class.getClassLoader()
				.getResourceAsStream(path);

		Properties p = new Properties();
		try { 
			p.load(is);
			return p.getProperty(propertiesName);

		} catch (IOException e) {
			e.printStackTrace();
		} finally {

			if (null != is) {
				try {
					is.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return null;
	}
 
}
